<template>
	<view class="container">
		<view class="address_view" @click="tenantAction()">
			{{ tenantName }}
			<image src="@/static/images/smartLock/addressIcon.png" mode=""
				style="width: 30rpx;height: 25rpx;margin-left: 10rpx;"></image>
		</view>
		<view class="list_view">
			<view class="item_view" v-for="(item,index) in dataList" :key="index">
				<view class="swiper_view">
					<view class="swiper_item_view">
						<view class="swiper_item_left_view">
							<image src="@/static/images/smartLock/lockBlue.png" style="width: 36rpx;height: 45rpx;"
								mode=""></image>
						</view>
						<view class="Text77" style="color: #FFFFFF;">
							{{ item.deviceName }}
						</view>
					</view>
					<view class="swiper_lock_view" @click="detailAction(item)">
						锁具详情
					</view>
				</view>
			</view>
		</view>
		<u-empty text="暂无数据" mode="list" v-if="dataList.length==0" :margin-top="300"></u-empty>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				tenantName: '',
				tenantId: '',
				dataList: [],
				pageNum: 1,
				pageSize: 10,
				total: 0,
				emptyPage: false,
			}
		},
		onShow() {
			var that = this
			uni.$on('seletedTenant', function(e) {
				that.tenantName = e.tenantName
				that.tenantId = e.tenantId
				that.pageNum = 1
				that.getLockListData()
			})
		},
		onLoad() {
			let sUserInfo = this.$storage.getStorageDataSync("sUserInfo")
			this.tenantId = sUserInfo.tenantId
			this.tenantName = sUserInfo.tenantName
			this.getLockListData();
		},
		methods: {
			tenantAction() {
				this.$Router.push({
					name: 'tenantIndex'
				})
			},
			detailAction(item) {
				this.$Router.push({
					name: 'deviceDetail',
					params: {
						deviceId: item.deviceId,
						deviceType: item.deviceType
					}
				})
			},
			onPullDownRefresh() {
				this.pageNum = 1
				this.getLockListData()
			},
			onReachBottom() {
				if (this.total <= this.pageNum * this.pageSize) {
					return
				}
				this.pageNum += 1
				this.getLockListData()
			},
			getLockListData() {
				var that = this
				this.$apis.getLockList({
					tenantId: this.tenantId,
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					deviceType: 'LOCK'
				}).then(result => {
					uni.stopPullDownRefresh();
					if (result.res.data.code == '200') {
						if (that.pageNum == 1) {
							that.dataList = [] //如果是第一页需手动制空列表
							if (result.res.data.rows.length == 0) that.emptyPage = true
						}
						that.total = result.res.data.total
						that.dataList = that.dataList.concat(result.res.data.rows)
					} else {
						that.$show.toastMessage(result.res.data.msg);
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		width: 100%;
		min-height: 100vh;
		box-sizing: border-box;
		background-color: #F8F8F8;
	}

	.address_view {
		padding: 10rpx 20rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		background-color: #FFFFFF;
	}

	.list_view {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;

		.item_view {
			width: 100%;
			padding: 30rpx 50rpx;
			padding-bottom: 0;

			.swiper_view {
				width: 100%;
				height: 160rpx;
				padding: 0 50rpx;
				position: relative;
				background-color: red;
				border-radius: 30rpx;
				background: linear-gradient(100deg, #2150C2 2.63%, #3C64B9 68.56%, #477DD5 95.71%);
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				align-items: center;

				.swiper_item_view {
					display: flex;
					flex-direction: row;
					justify-content: center;
					align-items: center;

					.swiper_item_left_view {
						display: flex;
						justify-content: center;
						align-items: center;
						width: 70rpx;
						height: 70rpx;
						border-radius: 35rpx;
						background-color: #FFFFFF;
						margin-right: 20rpx;
					}
				}

				.swiper_lock_view {
					line-height: 34rpx;
					padding: 10rpx 26rpx;
					color: #FFFFFF;
					font-size: 24rpx;
					border-radius: 43rpx;
					border: 2rpx solid #FFFFFF;
				}
			}
		}
	}
</style>